﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;



/// <summary>
/// 缓存接口
/// </summary>
public interface ICache
{
    #region Remove
    /// <summary>
    /// 获取所有key
    /// </summary>
    /// <returns></returns>
    IEnumerable<string> GetAllKeys();

    /// <summary>
    /// 用于在 key 存在时删除 key
    /// </summary>
    /// <param name="key">键</param>
    long Remove(params string[] key);

    /// <summary>
    /// 用于在 key 存在时删除 key
    /// </summary>
    /// <param name="key">键</param>
    /// <returns></returns>
    Task<long> RemoveAsync(params string[] key);

    /// <summary>
    /// 用于在 key 模板存在时删除
    /// </summary>
    /// <param name="pattern">key模板</param>
    /// <returns></returns>
    Task<long> RemoveByPatternAsync(string pattern);


    /// <summary>
    /// 删除以 str开头的key
    /// </summary>
    /// <param name="str"></param>
    /// <returns></returns>
    Task<long> RemoveStartWithAsync(string str);
    #endregion

    /// <summary>
    /// 获取配比的key
    /// </summary>
    /// <param name="pattern">*号配比任一字符</param>
    /// <returns></returns>
    Task<IEnumerable<string>> GetKeys(string pattern);

    #region Exists
    /// <summary>
    /// 检查给定 key 是否存在
    /// </summary>
    /// <param name="key">键</param>
    /// <returns></returns>
    bool Exists(string key);

    /// <summary>
    /// 检查给定 key 是否存在
    /// </summary>
    /// <param name="key">键</param>
    /// <returns></returns>
    Task<bool> ExistsAsync(string key);

    #endregion

    #region Get
    /// <summary>
    /// 获取指定 key 的值
    /// </summary>
    /// <param name="key">键</param>
    /// <returns></returns>
    object? Get(string key);

    /// <summary>
    /// 获取指定 key 的值
    /// </summary>
    /// <typeparam name="T">byte[] 或其他类型</typeparam>
    /// <param name="key">键</param>
    /// <returns></returns>
    T? Get<T>(string key);

    /// <summary>
    /// 获取指定 key 的值
    /// </summary>
    /// <param name="key">键</param>
    /// <returns></returns>
    Task<object?> GetAsync(string key);

    /// <summary>
    /// 获取指定 key 的值
    /// </summary>
    /// <typeparam name="T">byte[] 或其他类型</typeparam>
    /// <param name="key">键</param>
    /// <returns></returns>
    Task<T?> GetAsync<T>(string key);

    #endregion

    #region Set
    /// <summary>
    /// 设置指定 key 的值，所有写入参数object都支持string | byte[] | 数值 | 对象
    /// </summary>
    /// <param name="key">键</param>
    /// <param name="value">值</param>
    bool Set(string key, object value);

    /// <summary>
    /// 设置指定 key 的值，所有写入参数object都支持string | byte[] | 数值 | 对象
    /// </summary>
    /// <param name="key">键</param>
    /// <param name="value">值</param>
    /// <param name="expire">有效期</param>
    bool Set(string key, object value, TimeSpan expire);

    /// <summary>
    /// 设置指定 key 的值，所有写入参数object都支持string | byte[] | 数值 | 对象
    /// </summary>
    /// <param name="key">键</param>
    /// <param name="value">值</param>
    /// <returns></returns>
    Task<bool> SetAsync(string key, object value);

    /// <summary>
    /// 设置指定 key 的值，所有写入参数object都支持string | byte[] | 数值 | 对象
    /// </summary>
    /// <param name="key">键</param>
    /// <param name="value">值</param>
    /// <param name="expire">有效期</param>
    /// <returns></returns>
    Task<bool> SetAsync(string key, object value, TimeSpan expire);



    #endregion
}


